#ifndef LABELSCENE_H
#define LABELSCENE_H
#include "polygonitem.h"
#include "vertexitem.h"
#include <QGraphicsScene>
#include <QMainWindow>
class LabelScene: public QGraphicsScene
{
    Q_OBJECT
public:
    enum Mode { CreatePolygon, CreateRectangle, EditPolygon };
    LabelScene(QObject *parent);
    void setMode(Mode mode);
    Mode mode(){ return myMode;}
    VertexItem* cursorFollower = nullptr;

public slots:

signals:
    void polygonCreated(PolygonItem *polygonItem);
    void modeChange(Mode mode);

protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
    void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
    void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
private:
    //when creating polygon or rectangle, "count" is the num of vertexes which user have created
    bool isItemChange(int type) const;
    // bool isImageOpen = false;
    int count = 0;
    bool isMoving = true;
    //initialize the point tracking the mouse movement of user

    PolygonItem* currentPolygonItem = nullptr;
    Mode myMode;
    bool isVertexOverlap(QPointF point);
    bool isDrawing() {return count > 0; }
    void createShadowPolygon();
    void addVertexToPolygon(VertexItem *vertex);
};

#endif // LABELSCENE_H
